#ifndef __CONDITION_H_
#define __CONDITION_H_
#include"Mutexlock.h"
#include"Noncopyable.h"

namespace SC
{
    class Condition :  Noncopyable
    {
    public:
        Condition(Mutexlock& mutex)
        : _mutex(mutex)
        {
            if(pthread_cond_init(&_cond, NULL))
                logError("pthread_cond_init");
        }
        ~Condition()
        {
            if(pthread_cond_destroy(&_cond))
                logError("pthread_condattr_destroy");
        }

        void wait()
        {
            if(pthread_cond_wait(&_cond, _mutex.getMutexPtr()))
                logError("pthread_cond_wait");
        }

        void wake()
        {
            if(pthread_cond_signal(&_cond))
                logError("pthread_cond_signal");
        }

        void wakeall()
        {
            if(pthread_cond_broadcast(&_cond))
                logError("pthread_cond_broadcast");
        }

    private:
        pthread_cond_t _cond;
        Mutexlock& _mutex;
    };
}

#endif